<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertDefinition name="dialog-layout">
	<tiles:putAttribute name="head">
		<script type="text/javascript">
			$(function() {
				$("#datepicker").datepicker({
					dateFormat : "yy-mm-dd"
				});

				$("#btnAddTeacher").click(function() {
					var firstPane = $(this).closest("div.teaching");

					var beginTime = firstPane.find(".beginTime").val();
					var endTime = firstPane.find(".endTime").val();

					var teachingPan = firstPane.next("div.teaching").clone();
					teachingPan.find(".beginTime").val(beginTime);
					teachingPan.find(".endTime").val(endTime);

					firstPane.after(teachingPan);

					teachingPan.find(".teachingTime").timepicker({
						defaultTime : '00:00',
						showMeridian : false
					});

					teachingPan.find("button").click(function() {
						$(this).closest("div.teaching").remove();
					});

					teachingPan.show();
				});

				$(".teaching").find("button.assigned").click(function() {
					$(this).closest("div.teaching").remove();
				});

				$(".lessonTime").timepicker({
					defaultTime : '09:00',
					showMeridian : false
				});

				$(".teachingTime").timepicker({
					defaultTime : '00:00',
					showMeridian : false
				});

				$("form").Validform({
					ajaxPost : true,
					tiptype : ValidUtils.siblingTip,
					callback : function(data) {
						helper.showMsg(data, {
							okHandler : function() {
								art.dialog.data("success", true);
								art.dialog.close();
							}
						});
					}
				});
			});
		</script>
		<style type="text/css">
#panTeaching {
	display: inline;
}

.teaching {
	margin-top: 1em;
}
</style>
	</tiles:putAttribute>
	<tiles:putAttribute name="mainBody">
		<form class="form-horizontal" action="doModifyLesson" method="post">
			<input type="hidden" value="${lesson.id}" name="id" />
			<fieldset>
				<legend>编辑课表</legend>
				<div class="control-group">
					<div class="control-label">序号</div>
					<div class="controls">
						<input type="text" name="no" value="${lesson.no}" /> <span class="help-block">同时间的课程将按照这个编号从大到小排列</span>
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">日期</div>
					<div class="controls">
						<input type="text" name="date" id="datepicker" value="${lesson.date}" />
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">起止时间</div>
					<div class="controls">
						<div class="input-append bootstrap-timepicker">
							<input name="beginTime" class="lessonTime input-small" type="text" value="${lesson.beginTimeStr}"> <span class="add-on"> <i class="icon-time"></i>
							</span>
						</div>
						<div class="input-append bootstrap-timepicker">
							<input name="endTime" class="lessonTime input-small" type="text" value="${lesson.endTimeStr}"> <span class="add-on"> <i class="icon-time"></i>
							</span>
						</div>
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">课程名称</div>
					<div class="controls">
						<input type="text" name="name" value="${lesson.name }" />
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">教员</div>
					<div class="controls">
						<s:iterator value="#lesson.teachings" var="teaching" status="status">
							<s:if test="#status.first">
								<div class="teaching" style="margin-top: 0">
									<select name="teacher">
										<s:iterator value="#teachers" var="t">
											<option value="${t.id}" <s:if test="#t.id == teacher.id">selected="selected"</s:if>>${t.name}</option>
										</s:iterator>
									</select>
									<div class="input-append bootstrap-timepicker">
										<input class="beginTime teachingTime input-small" name="teachingBeginTime" type="text" value="${teaching.beginTimeStr}"> <span class="add-on"> <i
											class="icon-time"></i>
										</span>
									</div>
									<div class="input-append bootstrap-timepicker">
										<input class="endTime teachingTime input-small" name="teachingEndTime" type="text" value="${teaching.endTimeStr}"> <span class="add-on"> <i
											class="icon-time"></i>
										</span>
									</div>
									<button id="btnAddTeacher" type="button">
										<i class="icon-plus"></i>
									</button>
								</div>
							</s:if>
							<s:else>
								<div class="teaching">
									<select name="teacher">
										<s:iterator value="#teachers" var="t">
											<option value="${t.id}" <s:if test="#t.id == teacher.id">selected="selected"</s:if>>${t.name}</option>
										</s:iterator>
									</select>
									<div class="input-append bootstrap-timepicker">
										<input class="beginTime teachingTime input-small" name="teachingBeginTime" type="text" value="${teaching.beginTimeStr}"> <span class="add-on"> <i
											class="icon-time"></i>
										</span>
									</div>
									<div class="input-append bootstrap-timepicker">
										<input class="endTime teachingTime input-small" name="teachingEndTime" type="text" value="${teaching.endTimeStr}"> <span class="add-on"> <i
											class="icon-time"></i>
										</span>
									</div>
									<button type="button" class="assigned">
										<i class="icon-minus"></i>
									</button>
								</div>
							</s:else>
						</s:iterator>
						<div class="teaching" style="display: none">
							<select name="teacher">
								<s:iterator value="#teachers" var="t">
									<option value="${t.id}">${t.name}</option>
								</s:iterator>
							</select>
							<div class="input-append  bootstrap-timepicker">
								<input class="beginTime teachingTime input-small" name="teachingBeginTime" type="text"> <span class="add-on"> <i class="icon-time"></i>
								</span>
							</div>
							<div class="input-append bootstrap-timepicker">
								<input class="endTime teachingTime input-small" name="teachingEndTime" type="text"> <span class="add-on"> <i class="icon-time"></i>
								</span>
							</div>
							<button type="button">
								<i class="icon-minus"></i>
							</button>
						</div>
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">教室</div>
					<div class="controls">
						<select name="classroom">
							<s:iterator value="#classrooms" var="t">
								<option value="${t.id}" <s:if test="#t.id == #lesson.classroom.id">selected="selected"</s:if>>${t.name}</option>
							</s:iterator>
						</select>
					</div>
				</div>
				<div class="control-group">
					<div class="control-label">所属课程类型</div>
					<div class="controls">
						<select name="courseType">
							<s:iterator value="#courseTypes" var="courseType">
								<option class="${courseType.cssClass}" value="${courseType.id}" <s:if test="id==#lesson.courseType.id">selected="selected" </s:if>>${courseType.name}</option>
							</s:iterator>
						</select>
					</div>
				</div>
			</fieldset>
			<div class="control-group">
				<div class="controls">
					<button type="submit" class="btn btn-primary">提交</button>
				</div>
			</div>
		</form>
	</tiles:putAttribute>
</tiles:insertDefinition>